package com.bj58.groupbuy.action.util;

import java.lang.reflect.Method;
import java.text.DecimalFormat;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.TreeMap;

import javax.servlet.http.HttpServletRequest;

import com.bj58.groupbuy.action.model.FusionChartsVO;

public class FusionChartsUtil {
	private VelocityTools vt = new VelocityTools();
	/**Line2D XML拼接
	 * @param vo
	 * @return
	 */
	public static String Line2D(FusionChartsVO  vo){
		
		StringBuffer  values = new StringBuffer();
		//节点值
		for(String kv : vo.getValues()){
			String[] key_value = kv.split("_");
			String key  = key_value[0];
			String value =  key_value[1];
			values.append("<set label=\"");
			values.append(key);
			values.append("\" value=\"");
			values.append(value);
			values.append("\"/>");
		}
		
		String xml ="<chart caption=\""+vo.getCaption()+"\" subcaption=\""+vo.getSubcaption()+"\" xAxisName=\""
		+vo.getxAxisName()+"\" yAxisName=\""+vo.getyAxisName()+"\" " +
		"alternateHGridColor=\"FCB541\" alternateHGridAlpha=\"20\"" +
		" divLineColor=\"FCB541\" divLineAlpha=\"50\" canvasBorderColor=\"666666\" baseFontColor=\"666666\"" +
		" lineColor=\"FCB541\" chartRightMargin=\"35\">" +
		 values.toString()+
		"<styles>" +
		"<definition>" +
		"<style name=\"Anim1\" type=\"animation\" param=\"_xscale\" start=\"0\" duration=\"1\"/>" +
		"<style name=\"Anim2\" type=\"animation\" param=\"_alpha\" start=\"0\" duration=\"0.6\"/>" +
		"<style name=\"DataShadow\" type=\"Shadow\" alpha=\"40\"/>" +
		"</definition>" +
		"<application>" +
		"<apply toObject=\"DIVLINES\" styles=\"Anim1\"/>" +
		"<apply toObject=\"HGRID\" styles=\"Anim2\"/>" +
		"<apply toObject=\"DATALABELS\" styles=\"DataShadow,Anim2\"/>" +
		"</application></styles></chart>";
		 return xml;
	}
	
	public static String Column2D(FusionChartsVO vo){
		StringBuffer  values = new StringBuffer();
		for(String kv : vo.getValues()){
			String[] key_value = kv.split("_");
			String key  = key_value[0];
			String value =  key_value[1];
			values.append("<set label=\"");
			values.append(key);
			values.append("\" value=\"");
			values.append(value);
			values.append("\"/>");
		}
		String xml="<chart palette=\"2\"  caption=\""+vo.getCaption()+"\" subcaption=\""+vo.getSubcaption()+"\" xAxisName=\""
							+vo.getxAxisName()+"\" yAxisName=\""+vo.getyAxisName()+"\" " +
							"decimals=\"2\" formatNumberScale=\"0\" useRoundEdges=\"1\">" +
							values.toString() +
							"</chart>";
		 return xml;
	}
	
	public static String Pie2D(List<String> kvList){
		StringBuffer  values = new StringBuffer();
		for(String key_value : kvList){
			String[] kv = key_value.split("_");
			values.append("<set label=\"");
			values.append(kv[0]);
			values.append("\" value=\"");
			values.append(kv[1]);
			values.append("\"/>");
		}
		 String xml = "<chart palette=\"4\">" +values.toString()  +"</chart>";
		 return xml;
	}
	
	public static String Muti_Series_Line2D(List<String>categorys, TreeMap<String,List<String>> kvMap){
		StringBuffer xml =new StringBuffer();
		//表头设置
		xml.append("<chart caption=\"\" subcaption=\"from "+categorys.get(0)+" to "+categorys.get(categorys.size()-1)+"\" lineThickness=\"1\" showValues=\"1\" ");
		xml.append("formatNumberScale=\"0\" anchorRadius=\"2\" divLineAlpha=\"20\" divLineColor=\"CC3300\" divLineIsDashed=\"1\" ");
		xml.append("showAlternateHGridColor=\"1\" alternateHGridAlpha=\"5\" alternateHGridColor=\"CC3300\" shadowAlpha=\"40\" ");
		xml.append("labelStep=\"1\" numvdivlines=\"5\" chartRightMargin=\"35\" bgColor=\"FFFFFF,CC3300\" bgAngle=\"270\" bgAlpha=\"10,10\"> ");
		//X轴设置
		xml.append("<categories>");
		for(String category : categorys){
			xml.append("<category label=\""+category+"\"/>");
		}
		xml.append("</categories>");
		
		//各曲线设置
		Iterator<String> it = kvMap.keySet().iterator();
		int index = 0;
		while(it.hasNext()){
			String name = it.next();
			xml.append("<dataset seriesName=\""+name+"\" color=\""+MyStore.getColors().get(index)+"\" anchorBorderColor=\""+MyStore.getColors().get(index)+"\" anchorBgColor=\""+MyStore.getColors().get(index)+"\">");
			List<String> kv = kvMap.get(name);
			
			for(String value : kv){
				xml.append("<set value=\""+value+"\"/>");
			}
			xml.append("</dataset>");
			index ++;
		}
		xml.append("<styles>");
		xml.append("<definition>");
		xml.append("<style name=\"CaptionFont\" type=\"font\" size=\"12\"/>");
		xml.append("</definition>");
		xml.append("<application><apply toObject=\"CAPTION\" styles=\"CaptionFont\"/><apply toObject=\"SUBCAPTION\" styles=\"CaptionFont\"/></application>");
		xml.append("</styles></chart>");
		return xml.toString();
	}
	
	
	
	public static String MSColumn2D(List<String>categorys, TreeMap<String,List<Integer>> kvMap){
		StringBuffer xml =new StringBuffer();
		xml.append("<chart palette=\"2\" caption=\"客服问题统计\" shownames=\"1\" showvalues=\"0\" decimals=\"0\"  useRoundEdges=\"1\" legendBorderAlpha=\"0\">");
		xml.append("<categories>");
		for(String category : categorys){
			xml.append("<category label=\""+category+"\"/>");
		}
		xml.append("</categories>");
		
		Iterator<String> it = kvMap.keySet().iterator();
		
		int colorIndex = 0;
		MyStore.getColors().get(colorIndex);
		while(it.hasNext()){
			String dateName = it.next();
			if(colorIndex > MyStore.getColors().size())
				colorIndex = 0;
			
			xml.append("<dataset seriesName=\""+dateName+"\" color=\""+MyStore.getColors().get(colorIndex)+"\" showValues=\"0\">");
			List<Integer> values = kvMap.get(dateName);
			for(Integer num : values){
				xml.append("<set value=\""+num+"\"/>");
			}
			xml.append("</dataset>");
			colorIndex++;
		}
		xml.append("</chart>");
		return xml.toString();
	}
	
	public static String MSColumn3DLineDY(List<String> xAxisList,TreeMap<String,List<String>> leftAxisValues,TreeMap<String,List<String>>rightAxisValues){
		StringBuffer xml =new StringBuffer();
		
		MyStore.getColors();
		xml.append("<chart palette=\"6\" caption=\"\" shownames=\"1\" showvalues=\"0\" numberPrefix=\"\" sYAxisValuesDecimals=\"2\" connectNullData=\"0\" PYAxisName=\"\" SYAxisName=\"\" numDivLines=\"6\" formatNumberScale=\"0\">");
		xml.append("<categories>");
		//X轴值
		for(String xa : xAxisList){
			xml.append("<category label=\""+xa+"\"/>");
		}
		xml.append("</categories>");
		//左Y轴
		Iterator<String> la = leftAxisValues.keySet().iterator();
		int indexCol = 0;
		while(la.hasNext()){
			String laName = la.next();
			List<String> laValues = leftAxisValues.get(laName);
			xml.append("<dataset seriesName=\""+laName+"\" color=\""+MyStore.colors.get(indexCol)+"\" showValues=\"0\">");
			for(String  laValue : laValues){
				xml.append("<set value=\""+laValue+"\"/>");
			}
			xml.append("</dataset>");
			indexCol++;
		}
//		xml.append("<dataset seriesName=\"Product A\" color=\""+MyStore.colors.get(0)+"\" showValues=\"0\">");
//		xml.append("<set value=\"25601.34\"/>");
//		xml.append("<set value=\"20148.82\"/>");
//		xml.append("<set value=\"17372.76\"/>");
//		xml.append("<set value=\"35407.15\"/>");
//		xml.append("<set value=\"38105.68\"/>");
//		xml.append("</dataset>");
		
		//右Y轴
		Iterator<String> ra = rightAxisValues.keySet().iterator();
		while(ra.hasNext()){
			String raName = ra.next();
			List<String> raValues = rightAxisValues.get(raName);
			xml.append("<dataset seriesName=\""+raName+"\" color=\""+MyStore.colors.get(indexCol)+"\" showValues=\"0\" parentYAxis=\"S\">");
			for(String  raValue : raValues){
				xml.append("<set value=\""+raValue+"\"/>");
			}
			xml.append("</dataset>");
			indexCol++;
		}
		
//		右Y轴
//		xml.append("<dataset seriesName=\"Total Quantity\" color=\"8BBA00\" showValues=\"0\" parentYAxis=\"S\">");
//		xml.append("<set value=\"45000\"/>");
//		xml.append("<set value=\"44835\"/>");
//		xml.append("<set value=\"42835\"/>");
//		xml.append("<set value=\"77557\"/>");
//		xml.append("<set value=\"92633\"/>");
//		xml.append("</dataset>");
		
		xml.append("</chart>");
		
		return xml.toString();
	}
	
	/**	/**双重Y轴图表绘图集合排序（不含特殊字段）
	 * @param <T>
	 * @param functions
	 * @param rsList
	 * @param clazz
	 * @param request
	 * @return
	 */
	public  static<T> TreeMap<String,TreeMap<String,List<String>>> SortingForNoExName  (String functions,List<T> rsList,Class<T> clazz , HttpServletRequest request){
		TreeMap<String,TreeMap<String,List<String>>>  rsMap = new TreeMap<String,TreeMap<String,List<String>>>();//最终已按数量级分类的结果集
		
		TreeMap<String,List<String>> subMap = new TreeMap<String,List<String>>();//未分类的结果级
		TreeMap<String,List<String>> leftMap = new TreeMap<String,List<String>>();//左轴集合
		TreeMap<String,List<String>> rightMap = new TreeMap<String,List<String>>();//右轴集合
		
		DecimalFormat df = new DecimalFormat("0.00");
		DecimalFormat df2 = new DecimalFormat("0");
		try{
			
/**********
 * 取出未分类的结果集subMap
 *********/
			//根据指标遍历取各项节点值
			String[] fs = functions.split(",");
			for(String  function : fs){
				List<String> tempList = new ArrayList<String>();
				for(T vo : rsList){
					//网购销售额单独计算
					if(function.equals("wgSales")){
						String methodName1 = "getPay_amount";
						String methodName2 = "getGroupbuy_amount";
		        		Method[] mm = clazz.getMethods();
		        		
		        		String Pay_amount = "";
		        		String Groupbuy_amount = "";
		        		for(Method m: mm){
							if(m.getName().equals(methodName1)){
								Pay_amount = m.invoke(vo).toString();
							}else if(m.getName().equals(methodName2)){
								Groupbuy_amount =  m.invoke(vo).toString();
							}
						}
						String value=String.valueOf(Integer.parseInt(df2.format(Double.valueOf(Pay_amount)))-Integer.parseInt(df2.format(Double.valueOf(Groupbuy_amount))));
						tempList.add(value);
					}else{
						String methodName = "get" +function.substring(0,1).toUpperCase()+ function.substring(1);
		        		Method[] mm = clazz.getMethods();
		        		
		        		for(Method m: mm){
							if(m.getName().equals(methodName)){
								String value  = m.invoke(vo).toString();
								if(value.indexOf(".") > -1 && !methodName.equals("getAmount_per_visits") &&  !methodName.equals("getCommission_per_visits") && !methodName.equals("getAvg_time_on_site")){
									if(Double.parseDouble(value) < 1  && Double.parseDouble(value) > 0 ){ //百分比率的指标
										value  = df.format(Double.parseDouble(value)*100);
									}else{ //其他指标，取整
										value = value.substring(0,value.indexOf("."));
									}
								}
								tempList.add(value);
							}
						}
					}
				}
				subMap.put(function, tempList);
			}
		

		/****
		 * 对取出来的未分类的结果集subMap进行分类得到leftMap和rightMap
		 * 根据其指标数量级分类决定其应该画何种图形表示
		***/			
			//按照各指标数量级进行分类
			//取出各项指标节点平均值
			List<String>  countSortList = new ArrayList<String>();
			Iterator<String>  it = subMap.keySet().iterator();
			while(it.hasNext()){
				String function  = it.next();
				List<String> sList = subMap.get(function);
				double sum = 0;
				for(String s : sList){
					sum = sum + Double.valueOf(s);
				}
				String value = (sum/sList.size())+"_"+function;
				countSortList.add(value);
			}
			
			double max = 0;
			for(String tem : countSortList){
				double now =Double.valueOf(tem.substring(0,tem.indexOf("_")));
				if(now > max){
					max = now;
				}
			}
			
			for(String tem : countSortList){
				double now =Double.valueOf(tem.substring(0,tem.indexOf("_")));
				String function =tem.substring(tem.indexOf("_")+1);
				if(max/now > 20){
					leftMap.put(function, subMap.get(function));
				}else{
					rightMap.put(function, subMap.get(function));
				}
			}
			
			if(leftMap.size() > 0){
				rsMap.put("left", leftMap);
			}
			rsMap.put("right", rightMap);
		}catch (Exception e) {
			e.printStackTrace();
		}
		return rsMap;
	}
	/**双重Y轴图表绘图集合排序（含特殊字段）(汇总)
	 * @param <T>
	 * @param functions
	 * @param rsList
	 * @param clazz
	 * @param request
	 * @param exname  特殊字段
	 * @return
	 */
	public  static<T> TreeMap<String,TreeMap<String,List<String>>> SortingForKExNameCountAll  (String functions,List<T> rsList,Class<T> clazz , HttpServletRequest request,String exname){
		TreeMap<String,TreeMap<String,List<String>>>  rsMap = new TreeMap<String,TreeMap<String,List<String>>>();//最终已按数量级分类的结果集
		
		TreeMap<String,List<String>> subMap = new TreeMap<String,List<String>>();//未分类的结果级
		TreeMap<String,List<String>> leftMap = new TreeMap<String,List<String>>();//左轴集合
		TreeMap<String,List<String>> rightMap = new TreeMap<String,List<String>>();//右轴集合
		
		DecimalFormat df = new DecimalFormat("0.00");
		try{
			//根据指标遍历取各项节点值
			String[] fs = functions.split(",");
			for(String  function : fs){
				String ind =  function.split(":")[1];//指标字段
				List<String> tempList = new ArrayList<String>();
				for(T vo : rsList){
					String methodName = "get" +ind.substring(0,1).toUpperCase()+ ind.substring(1);
	        		Method[] mm = clazz.getMethods();
	        		
	        		boolean isSource = true;
	        		if(isSource){
	        			for(Method m: mm){
							if(m.getName().equals(methodName)){
								String value  = m.invoke(vo).toString();
								
								if(value.indexOf(".") > -1){
									if(Double.parseDouble(value) < 1 && !ind.equals("per_visit_amount")){ //百分比率的指标
										value  = df.format(Double.parseDouble(value)*100);
									}else{ //其他指标，取整
										value = value.substring(0,value.indexOf(".")+2);
									}
								}
								tempList.add(value);
							}
						}
	        		}
				}
				subMap.put(function, tempList);
			}
//			rsMap.put("left", subMap);
		
			//按照各指标数量级进行分类
			//取出各项指标节点平均值
			List<String>  countSortList = new ArrayList<String>();
			Iterator<String>  it = subMap.keySet().iterator();
			while(it.hasNext()){
				String function  = it.next();
				List<String> sList = subMap.get(function);
				double sum = 0;
				for(String s : sList){
					sum = sum + Double.valueOf(s);
				}
				String value = (sum/sList.size())+"_"+function;
				countSortList.add(value);
			}
			
			double max = 0;
			for(String tem : countSortList){
				double now =Double.valueOf(tem.substring(0,tem.indexOf("_")));
				if(now > max){
					max = now;
				}
			}
			
			for(String tem : countSortList){
				double now =Double.valueOf(tem.substring(0,tem.indexOf("_")));
				String function =tem.substring(tem.indexOf("_")+1);
				if(max/now > 20){
					leftMap.put(function, subMap.get(function));
				}else{
					rightMap.put(function, subMap.get(function));
				}
			}
			
			if(leftMap.size() > 0){
				rsMap.put("left", leftMap);
			}
			rsMap.put("right", rightMap);
		}catch (Exception e) {
			e.printStackTrace();
		}
		return rsMap;
	}
	
	
	
	/**双重Y轴图表绘图集合排序（含特殊字段）
	 * @param <T>
	 * @param functions
	 * @param rsList
	 * @param clazz
	 * @param request
	 * @param exname  特殊字段
	 * @return
	 */
	public  static<T> TreeMap<String,TreeMap<String,List<String>>> SortingForKExName  (String functions,List<T> rsList,Class<T> clazz , HttpServletRequest request,String exname){
		TreeMap<String,TreeMap<String,List<String>>>  rsMap = new TreeMap<String,TreeMap<String,List<String>>>();//最终已按数量级分类的结果集
		
		TreeMap<String,List<String>> subMap = new TreeMap<String,List<String>>();//未分类的结果级
		TreeMap<String,List<String>> leftMap = new TreeMap<String,List<String>>();//左轴集合
		TreeMap<String,List<String>> rightMap = new TreeMap<String,List<String>>();//右轴集合
		
		DecimalFormat df = new DecimalFormat("0.00");
		try{
			//根据指标遍历取各项节点值
			String[] fs = functions.split(",");
			for(String  function : fs){
				String source = function.split(":")[0]; 
				String ind =  function.split(":")[1];//指标字段
				List<String> tempList = new ArrayList<String>();
				for(T vo : rsList){
					String methodName = "get" +ind.substring(0,1).toUpperCase()+ ind.substring(1);
	        		Method[] mm = clazz.getMethods();
	        		
	        		boolean isSource = false;
	        		for(Method m: mm){
						if(m.getName().equals("get"+exname)){
							String value  = m.invoke(vo).toString();
							if(value.equals(source)){
								isSource = true;
							}
						}
	        		}
	        		if(isSource){
	        			for(Method m: mm){
							if(m.getName().equals(methodName)){
								String value  = m.invoke(vo).toString();
								
								if(value.indexOf(".") > -1){
									if(Double.parseDouble(value) < 1 && !ind.equals("per_visit_amount")){ //百分比率的指标
										value  = df.format(Double.parseDouble(value)*100);
									}else{ //其他指标，取整
										value = value.substring(0,value.indexOf(".")+2);
									}
								}
								tempList.add(value);
							}
						}
	        		}
				}
				subMap.put(function, tempList);
			}
//			rsMap.put("left", subMap);
		
			//按照各指标数量级进行分类
			//取出各项指标节点平均值
			List<String>  countSortList = new ArrayList<String>();
			Iterator<String>  it = subMap.keySet().iterator();
			while(it.hasNext()){
				String function  = it.next();
				List<String> sList = subMap.get(function);
				double sum = 0;
				for(String s : sList){
					sum = sum + Double.valueOf(s);
				}
				String value = (sum/sList.size())+"_"+function;
				countSortList.add(value);
			}
			
			double max = 0;
			for(String tem : countSortList){
				double now =Double.valueOf(tem.substring(0,tem.indexOf("_")));
				if(now > max){
					max = now;
				}
			}
			
			for(String tem : countSortList){
				double now =Double.valueOf(tem.substring(0,tem.indexOf("_")));
				String function =tem.substring(tem.indexOf("_")+1);
				if(max/now > 20){
					leftMap.put(function, subMap.get(function));
				}else{
					rightMap.put(function, subMap.get(function));
				}
			}
			
			if(leftMap.size() > 0){
				rsMap.put("left", leftMap);
			}
			rsMap.put("right", rightMap);
		}catch (Exception e) {
			e.printStackTrace();
		}
		return rsMap;
	}
	
	
	/**  智能报表  曲线图处理
	 * @param rsList   数据结果集
	 * @param cols  查询项
	 * @param dicMap 字段中英文字典
	 * @return
	 * @throws Exception
	 */
	public String XMLForIRbyMSColumn (List<String> rsList ,List<String> cols, Map<String,String> dicMap)throws Exception{
		
		TreeMap<String,TreeMap<String,List<String>>>  rsMap = new TreeMap<String,TreeMap<String,List<String>>>();//最终已按数量级分类的结果集
		TreeMap<String,List<String>> subMap = new TreeMap<String,List<String>>();//未分类的结果级
		TreeMap<String,List<String>> leftMap = new TreeMap<String,List<String>>();//左轴集合
		TreeMap<String,List<String>> rightMap = new TreeMap<String,List<String>>();//右轴集合
		
		//字典是 中文：英文 类型的  先反转
		Map<String,String> newDicMap = new HashMap<String, String>();
		for(Iterator<String> key = dicMap.keySet().iterator(); key.hasNext();){
			String cname = key.next();
			String ename = dicMap.get(cname);
			newDicMap.put(ename, cname);
		}
		
		//按照其排位数 对 结果集进行分类
		Map<Integer,List<String>>  tempRsMap = new HashMap<Integer, List<String>>();
		for(int i  = 0 ;  i < rsList.size(); i++){
			String[] tempValues = rsList.get(i).split(";");
			for(int j = 0 ; j < tempValues.length ; j++){
				List<String> tempList = new ArrayList<String>();
				if(tempRsMap.containsKey(j)){
					tempList = tempRsMap.get(j);
				}
				//数据结果处理
				int tempType = Integer.parseInt(tempValues[j].split(",")[1]);
				String realValue = tempValues[j].split(",")[0];
				switch (tempType) {
				case 1:
					realValue  = vt.comIntNOS(realValue);
					break;
				case 2:
					realValue  = vt.comFloat(realValue);
					break;
				case 3:
					realValue  = vt.comRate(realValue);
					if(realValue.contains("%")){
						realValue = realValue.replace("%", "");
					}
					break;
				}
				if("--".equals(realValue)){
					realValue = "0";
				}
				tempList.add(realValue);
				tempRsMap.put(j, tempList);
			}
		}
		
		//根据排位数， 获取对应的结果集
		for(int i = 1 ; i < cols.size() ; i ++){
			String col  = cols.get(i);
			if("groupBy".equals(col)){
				continue;
			}
			String typeName = newDicMap.get(col);//中文名
			subMap.put(typeName, tempRsMap.get(i));
		}
		
		//按照各指标数量级进行分类
		//取出各项指标节点平均值
		List<String>  countSortList = new ArrayList<String>();
		Iterator<String>  it = subMap.keySet().iterator();
		while(it.hasNext()){
			String function  = it.next();
			List<String> sList = subMap.get(function);
			double sum = 0;
			for(String s : sList){
				sum = sum + Double.valueOf(s);
			}
			String value = (sum/sList.size())+"_"+function;
			countSortList.add(value);
		}
		
		double max = 0;
		for(String tem : countSortList){
			double now =Double.valueOf(tem.substring(0,tem.indexOf("_")));
			if(now > max){
				max = now;
			}
		}
		
		for(String tem : countSortList){
			double now =Double.valueOf(tem.substring(0,tem.indexOf("_")));
			String function =tem.substring(tem.indexOf("_")+1);
			if(max/now > 20){
				leftMap.put(function, subMap.get(function));
			}else{
				rightMap.put(function, subMap.get(function));
			}
		}
		
		if(leftMap.size() > 0){
			rsMap.put("left", leftMap);
		}
		rsMap.put("right", rightMap);
		
		/** 数据分类完毕  开始匹配数据结果 */
		List<String> xAxisList =  tempRsMap.get(0); //X轴集合 （时间）
		TreeMap<String,List<String>> leftAxisValues = new TreeMap<String,List<String>>(); //左轴集合
		TreeMap<String,List<String>> rightAxisValues = new TreeMap<String,List<String>>();//右轴集合
	
		rightAxisValues = rsMap.get("right");
		if(rsMap.size() > 1){
			leftAxisValues = rsMap.get("left");
		}
		String xml  = "";//XML图形结果
		//双Y轴数量级时
		if(leftAxisValues.size() > 0){
			xml = FusionChartsUtil.MSColumn3DLineDY(xAxisList, leftAxisValues, rightAxisValues);
			xml = "LINEDY:"+xml;
		}else{//单Y轴数量级时
			xml = FusionChartsUtil.Muti_Series_Line2D(xAxisList, rightAxisValues);
			xml = xml.replace("showValues=\"1\"", "showValues=\"0\"");
			xml = "LINE2D:"+xml;
		}
		return xml;
	}
	
	
	
	/**  智能报表 饼图处理
	 * @param rsList   数据结果集  结构=  中文名;值,数据类型(1=int,2=double,3=百分比)
	 */
	public String XMLForIRbyPie (List<String> rsList)throws Exception{
		List<String> pies = new ArrayList<String>(); //结果集  类别_数字 的方式   按数字升序放入
		
		String xml = "";//图形结果 
		for(int i = 0 ; i < rsList.size() ; i ++){  //
			String[] tempValues = rsList.get(i).split(";");
			if(tempValues.length != 2){ //一般默认只有2项   维度 & 数值
				break;
			}
			String name = tempValues[0].split(",")[0];
			String value = tempValues[1].split(",")[0];
			int valueTyep =Integer.parseInt(tempValues[1].split(",")[1]);
			switch (valueTyep) {
			case 1:
				value  = vt.comIntNOS(value);
				break;
			case 2:
				value  = vt.comFloat(value);
				break;
			case 3:
				value  = vt.comRate(value);
				if(value.contains("%")){
					value = value.replace("%", "");
				}
				break;
			}
			
			if("--".equals(value)){
				value = "0";
			}
			
			pies.add(name+"_"+value);
		}
		pies = SortUtil.DescendByCount(pies, 20);
		//拼写xml
		xml = FusionChartsUtil.Pie2D(pies);
		return xml;
	}
	
}
